/*
 * CS_SOCIAL_SUMMON_FROM_FRIEND.cpp
 *
 *  Created on: 2013. 10. 21.
 *      Author: the2
 */



#include "../../Command.h"
#include "../../User.h"
#include "../../Proxy.h"
#include "../../NLogic/Space.h"

namespace ProjectZ { namespace NCommand {
/*
// 친구 소환
// A->SERVER: CS_SOCIAL_SUMMON_FRIEND
// SERVER->B: SC_SOCIAL_SUMMON_FROM_FRIEND
// B->SERVER: CS_SOCIAL_SUMMON_FROM_FRIEND
// SERVER->A: SC_SOCIAL_SUMMON_FRIEND
CS_SOCIAL_SUMMON_FROM_FRIEND				0x2138
{
	u32 u32gid;						// 상대방 GID
	u8 u8confirm					// 0 : reject , 1 : confirm, 2 : 참여중
}

SC_SOCIAL_SUMMON_FRIEND				0x2129
{
	s16 s16ack;
	u32 u32gid;						// 상대방 GID
	u8 u8confirm					// 0 : reject , 1 : confirm , 2 : 참여중
}
*/
void Command::CS_SOCIAL_SUMMON_FROM_FRIEND(User * pUser, ::Network::Packet * pPacket)
{
	PREPARE_PACKET;

	uint32_t reqRecallUserSeq = 0;	// 상대방 GID
	uint8_t is_accept = 0;

	*pPacket >> reqRecallUserSeq >> is_accept;

	User * pReceiver = NProxy::GetUser(reqRecallUserSeq);
	if(NULL == pReceiver)
	{
		return;
	}

	if(0 == is_accept)
	{
		NLogic::Space * pSpace = pReceiver->GetReserveSpace();
		if(NULL != pSpace)
		{
			pSpace->EraseReserveUser(pReceiver);
			pReceiver->SetReserveSpace(NULL);
		}
	}

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();

	*pAck << static_cast<int16_t>(ACK_OK) << reqRecallUserSeq << is_accept;

	pAck->MakePacket(CMD_SC_SOCIAL_SUMMON_FRIEND);
	pReceiver->Send(pAck);

//	ProjectZ::NProxy::RecallAck(pUser->GetUserSeq(), target_seq, is_accept);
//
//	if(1 == is_accept)
//		pUser->SetEnumState(User::EnumState::RECALL);
}

} /*NCommand*/ } /*ProjectZ*/
